local skel = fk.CreateSkill {
  name = "emo__dingchao",
  tags = {Skill.Lord},
}

Fk:loadTranslationTable{
  ["emo__dingchao"] = "定潮",
  [":emo__dingchao"] = "主公技，吴势力角色的回合开始时，你可以<a href='readying_card'>蓄势一张牌</a>并移动“御江”至其。",

  ["readying_card"] = "蓄势一张牌：弃置一张牌并令蓄势进度+1",
  ["#emo__dingchao-cost"] = "定潮：你可以蓄势一张牌并将移动“御江”至 %src",

  ["$emo__dingchao1"] = "凡日月所照，江河所至，皆为大吴疆土！",
}

local DIY = require "packages.diy_utility.diy_utility"

skel:addEffect(fk.TurnStart, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and not target.dead and target.kingdom == "wu"
    and not target:hasSkill("emo__yujiang", true)
    and table.find(player.room.alive_players, function (p) -- 除该角色外，有角色有“御江”
      return p:hasSkill("emo__yujiang", true)
    end)
    -- 必须有技能处于蓄势状态
    and table.find(player:getSkillNameList(), function (s) return DIY.isReadying (player, s) end) ~= nil
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cards = room:askToDiscard(player, {
      skill_name = skel.name, min_num = 1, max_num = 1, skip = true, cancelable = false, include_equip = true,
      prompt = "#emo__dingchao-cost:" .. target.id
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards, tos = {target} })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cost_data = event:getCostData(self)
    local cards = cost_data.cards
    if not cards then return end
    room:throwCard(cards, skel.name, player, player)
    for _, skill in ipairs(player:getSkillNameList()) do
      if DIY.isReadying (player, skill) then
        DIY.changeReadyProgress (player, skill, 1, skel.name)
        break
      end
    end
    for _, p in ipairs(room.alive_players) do
      if p:hasSkill("emo__yujiang", true) and p ~= target then
        room:doIndicate(p, {target})
        room:handleAddLoseSkills(p, "-emo__yujiang")
        room:handleAddLoseSkills(target, "emo__yujiang")
        break
      end
    end
  end,
})

return skel
